//
//  MeViewController.m
//  SIPphone
//
//  Created by wrt on 13-11-27.
//  Copyright (c) 2013年 wrtsoft. All rights reserved.
//

#import "MeViewController.h"
#import "SIPInterface.h"

@interface MeViewController ()

@end

@implementation MeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        self.title = NSLocalizedString(@"Me", @"我 Me");
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.segmentControl = [[HMSegmentedControl alloc] initWithSectionTitles:@[NSLocalizedString(@"online", @"在线 Online"),NSLocalizedString(@"busy", @"繁忙 Busy"),NSLocalizedString(@"DNDST", @"勿扰 DNDST"),NSLocalizedString(@"out", @"外出 Out"),NSLocalizedString(@"offline", @"离线 Offline")]];
    [self.segmentControl setFont:[UIFont systemFontOfSize:14]];
    [self.segmentControl setFrame:CGRectMake(90, 170, 220, 33)];
    [self.segmentControl setSelectionIndicatorHeight:3.5f];
    [self.segmentControl setBackgroundColor:[UIColor whiteColor]];
    [self.segmentControl setTextColor:[UIColor colorWithRed:83/255.0 green:215/255.0 blue:105/255.0 alpha:1.0]];
    [self.segmentControl setSelectionIndicatorColor:[UIColor colorWithRed:83/255.0 green:215/255.0 blue:105/255.0 alpha:1.0]];
    [self.segmentControl setSelectionIndicatorMode:HMSelectionIndicatorFillsSegment];
    [self.segmentControl addTarget:self action:@selector(segamentSelectChanged:) forControlEvents:UIControlEventValueChanged];
    [self.segmentControl setSegmentEdgeInset:UIEdgeInsetsMake(0, 6, 0, 6)];
    [self.view addSubview:self.segmentControl];
    
    
    
    
    //获取存在程序内的用户名和密码/ip/端口
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *tempUserName = [[NSString alloc] init];
    tempUserName = [defaults valueForKey:@"SAVEUSERNAME"];
    
    NSString *tempIp = [[NSString alloc] init];
    tempIp = [defaults valueForKey:@"SAVEIPADDRESS"];
    
    NSString *tempDisplayName = [[NSString alloc] init];
    tempDisplayName = [defaults valueForKey:@"SAVEDISPLAYNAME"];
    
    self.userNameLabel.text = tempUserName;
    self.displayNameLabel.text = tempDisplayName;
    self.ipLabel.text = tempIp;
    
    
    long status = [defaults integerForKey:@"SAVEMYSTATUS"];
    
    if (status == 1)
    {
        [self.segmentControl setSelectedIndex:0];
    }
    else if (status == 2)
    {
        [self.segmentControl setSelectedIndex:1];
    }
    else if (status == 7)
    {
        [self.segmentControl setSelectedIndex:2];
    }
    else if (status == 6)
    {
        [self.segmentControl setSelectedIndex:3];
    }
    else if (status == 0)
    {
        [self.segmentControl setSelectedIndex:4];
    }
}

- (IBAction)segamentSelectChanged:(HMSegmentedControl *)segmentedControl
{
    
    SIPInterface *interface = [SIPInterface shareSIPInterface];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if (segmentedControl.selectedIndex == 0)
    {
        [interface setMyStatusWithInt:1];
        [defaults setInteger:1  forKey:@"SAVEMYSTATUS"];
    }
    else if (segmentedControl.selectedIndex == 1)
    {
        [interface setMyStatusWithInt:2];
        [defaults setInteger:2  forKey:@"SAVEMYSTATUS"];
    }
    else if (segmentedControl.selectedIndex == 2)
    {
        [interface setMyStatusWithInt:7];
        [defaults setInteger:7  forKey:@"SAVEMYSTATUS"];
    }
    else if (segmentedControl.selectedIndex == 3)
    {
        [interface setMyStatusWithInt:6];
        [defaults setInteger:6  forKey:@"SAVEMYSTATUS"];
    }
    else if (segmentedControl.selectedIndex == 4)
    {
        [interface setMyStatusWithInt:0];
        [defaults setInteger:0  forKey:@"SAVEMYSTATUS"];
    }
    [defaults synchronize];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
